import { Inject, Controller, Get, Post, Body, Query } from '@midwayjs/core'
import { Context } from '@midwayjs/koa'
import { UserService } from '../service/user.service.js'

@Controller()
export class APIController {
  @Inject()
  ctx: Context

  @Inject()
  userService: UserService

  @Post('/auth/login')
  async login(@Body() data) {
    return this.userService.login(data)
  }

  @Post('/auth/register')
  async register(@Body() data) {
    return this.userService.register(data)
  }

  @Post('/insertUser')
  async insertUser(@Body() data) {
    return this.userService.insertMany([data])
  }

  @Get('/findUsers')
  async findUsers(@Query() query) {
    return this.userService.find(query)
  }

  @Post('/updateUser')
  async updateUser(@Body() data): Promise<any> {
    return this.userService.updateOne(data)
  }

  @Post('/deleteUser')
  async deleteUser(@Body() data): Promise<any> {
    return this.userService.deleteOne(data)
  }
}
